**************************************************************************************
	;Header frs File-linken

	IFD	Flag_project
Flag_WaterPara	set 1
	ENDC
	IFND	Flag_WaterPara
Flag_WaterPara	set 0
	ENDC
	IFEQ	Flag_WaterPara
Flag_WaterPara	set 1
	include	Nutz_project
	ELSEIF
**************************************************************************************
;CLOUD_PER_SPRITE	EQU	6
;CLOUD_UPPER_CLIP	EQU	26
;CLOUD_LOWER_CLIP	EQU	310

;		rsreset
;Sprite_X_Position	rs.w	1
;Sprite_Y_Position	rs.w	1
;Sprite_Speed_Ist	rs.w	1
;Sprite_Speed_Soll	rs.w	1
;Sprite_Float		rs.w	1
;Sprite_Offset		rs.w	1
;Sprite_Timer		rs.w	1
;Sprite_Reset		rs.w	1
;SPRITE_ENTRY_LENGTH	rs.w	0
;
			rsreset
WLax_Gfx_Anf		rs.w	1	;Anf Adr der GFX
WLax_Copper_Entry1	rs.w	1	;Adresse des CopperAbschnittes1
WLax_Y_WaitPos		rs.w	1	;Y_Position fr Wait
WLax_Pos_Val		rs.w	1	;Bere Pos  ScreenPos*Val/16
WLax_Max_Hight		rs.w	1	;Aktuelle Hhe des Lax
WLAX_ENTRYLENGTH		rs.w	0
WLAX_END			=	-1
;
;			rsreset
;Lax_Akt_Gfx		rs.w	1	;Gfx Adr die initialisiert wird
;Lax_Softpos		rs.w	1	;SoftPosition dieser Ebene
;Lax_Act_Y		rs.w	1
WLAX_VARILENGTH		rs.w	0
*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
		rsreset
Bubble_Height	rs.w	1
Bubble_Offset	rs.w	1
Bubble_Speed	rs.w	1
Bubble_Float	rs.w	1
Bubble_Zhler	rs.w	1
Bubble_Zhler_Reset	rs.w	1
Bubble_Pointer	rs.l	1
Bubble_Reset	rs.l	1
Bubble_Sprite_1	rs.l	1
Bubble_Sprite_2	rs.l	1
Bubble_Vertical	rs.l	1
BUBBLE_ENTRY_LENGTH	rs.w	0

;--------------------------------------------------------------------------

		rsset	Task_Buffer
Water_CopperList1	rs.b	17*6
Water_CopperList2	rs.b	17*6
WCopper_Buffer		rs.l	1
WCopper_Help		rs.b	6
WCopper_TabPointer	rs.l	1
WYPos_Pointer		rs.l	1
WYPos_Buffer		rs.l	1
WYPos_Table1		rs.w	42
WYPos_Table2		rs.w	42
;Cloud_Liste_1		rs.b	SPRITE_ENTRY_LENGTH*CLOUD_PER_SPRITE+2
;Cloud_Zeiger_Liste	rs.l	3
Bubble_Zeiger_Liste	rs.b	BUBBLE_ENTRY_LENGTH*4+200
Bubble_Pos_Offset	rs.w	1
WLax_Variables		rs.b	16*LAX_ENTRYLENGTH
WCopper_Wabbel		rs.w	20
WCopper_Struktur	rs.w	20*6
Water_Fade_Struktur	rs.b	FADE_SIZEOF+49*6
Water_YHelp		rs.w	7*2

YStart			rs.w	1
Water_Wobble		rs.w	224

MakeWaterPara:
	tst.b	Dont_render_Parallax(a6)
	bne	.only_colors

		bsr	Generate_Wabbel

		*--*>Get Bases
		*--*>Calculate Global Verschiebung

		moveq	#0,d5
		move	Scr_Y_Max(a6),d5
		move	#WGLOBAL_SCRVAL,d6
		divu	d6,d5		;jede d5 Front Pix
					;wird 1 back Pix gescrollt
		moveq	#0,d6
		move	Scr_Y_Level_Pos(a6),d6
		divu	d5,d6		;GLOBAL ScrollVal in d6

		lea	WLax_Entry_Tab,a0
		lea	WLax_Variables(a6),a5
		lea	WMaxLAX_ScrollVals,a1
		move	WAnzParaLax,d7
		moveq	#0,d3
.Bere_Y_AnfPos_loop	*---*>Y_Anf_Pos_Berechnen
		*--Calc LAX Verschiebung
		move	WLax_Y_WaitPos(a0),d0
		move	d3,d1
		add	d1,d1
		move	(a1,d1),d2
		beq.s	.NoZERO
		moveq	#0,d1
		move	Scr_Y_Max(a6),d1
		sub	#9*16,d1
		add	#208,d1		;***!!!
		divu	d2,d1		;jede d1 Front Pix wird 1 LAX Pix gescrollt

		moveq	#0,d2
		move	Scr_Y_Level_Pos(a6),d2
		divu	d1,d2		;LAX ScrollVal in d2

.NoZERO		*--*>Global Scroll und Lax Scroll abziehen abziehen
		sub	d6,d0
		sub	d2,d0
		move	d0,Lax_Act_Y(a5)
		add	#WLAX_ENTRYLENGTH,a0
		add	#WLAX_VARILENGTH,a5
		addq	#1,d3
		dbf	d7,.Bere_Y_AnfPos_loop

*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
		*--*>Search first Entry and Bere GFX Offset
		lea	WLax_Entry_Tab,a0
		lea	WLax_Variables(a6),a5

		move	WAnzParaLax,d7
.Search_Anfang	*---*>Y_Anf_Pos_Suchen
		move	Lax_Act_Y(a5),d0
		bmi.s	.Next_Entry
		cmp	#$2f,d0
		blo.s	.Next_Entry
		bra.s	.Entry_Found
.Next_Entry	*--*>Test Next Entry
		add	#WLAX_ENTRYLENGTH,a0
		add	#WLAX_VARILENGTH,a5
		dbf	d7,.Search_Anfang
*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.Entry_Found	*--*>Testen ob dieser oder vorheriger ?
		cmp	#$2f,d0
		beq.s	.THISONE
		*---*>Get Previous ENTRY
		sub	#WLAX_ENTRYLENGTH,a0
		sub	#WLAX_VARILENGTH,a5
		addq.w	#1,d7
		*--Bere Akt GFX Anf
		move	Lax_Act_Y(a5),d0
		sub	#$2f,d0
		neg	d0
		add.w	WLax_Gfx_Anf(a0),d0
		move.w	d0,Lax_Akt_Gfx(a5)
		move	#$2f,Lax_Act_Y(a5)
		bra.s	.Continue
.THISONE		*--*>Ist gerade oben
		move.w	WLax_Gfx_Anf(a0),Lax_Akt_Gfx(a5)
		moveq	#0,d0

.Continue		*--*>diesen Split in SLOT TAB eintragen
		move.l	WCopper_Buffer(a6),a2
		addq.l	#4,a2
		move.l	WYPos_Buffer(a6),a1
		lea	Water_YHelp(a6),a4

*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
.Init_Loop	*---*>INIT WaitPos and Softpos and GFX Adr
		*--Softscroll machen
		move	Scr_X_Level_Pos(a6),d0
		mulu	WLax_Pos_Val(a0),d0		;Pos*Val/16
		lsr	#4,d0
		move	d0,d1
		addq.w	#1,d1
		neg.w	d1
		and.l	#$ffff,d1
		divu	#80,d1
		swap	d1
		sub.w	#80,d1
		move	d1,Lax_Softpos(a5)

		*--Testen ob Offset auf GFX berechnet werden mu
.NO_OFFSET_BERE	*--WaitPos in Copper und COPPER SLOT schreiben
		move	Lax_Act_Y(a5),d0
		sub.w	#$2f,d0
		beq.s	.no_copper_entry
		move.w	d0,(a2)
		addq.l	#6,a2				;Zum nchsten Copper-Eintrag
		move.w	d0,(a4)+
.no_copper_entry:
		move.w	Lax_Softpos(a5),(a4)+

		*--Adr in Copper schreiben
		move.w	Lax_Akt_Gfx(a5),d1
		sub.w	d0,d1

		move.w	d1,(a1)+
		move.w	Lax_Softpos(a5),(a1)+
		move.w	WLax_Copper_Entry1(a0),(a1)+

		add	#WLAX_ENTRYLENGTH,a0
		add	#WLAX_VARILENGTH,a5
		*--*>testen ob Diese Letzter Eintrag ist ?
		cmp	#$2f+222,Lax_Act_Y(a5)
		bhi.s	.LAST_ENTRY
		move.w	WLax_Gfx_Anf(a0),Lax_Akt_Gfx(a5)
		dbf	d7,.Init_Loop
		*--*>Last Entry
.LAST_ENTRY
		move.w	#224,(a4)
		move.w	#$ff,(a2)+			;Copper-List abschlieen
;		move.l	#Int_Nop,(a2)
		clr.l	(a1)+
		clr.l	(a1)+

	move.l	WYPos_Buffer(a6),a0
	move.l	WYPos_Pointer(a6),WYPos_Buffer(a6)
	move.l	a0,WYPos_Pointer(a6)
	move.l	WCopper_Buffer(a6),a0
	move.l	Copper_List(a6),WCopper_Buffer(a6)
	move.l	a0,Copper_List(a6)


	; Input : a0 = Source-Adress
	;	d0 = Source-Len
	;	a1 = Dest-Adress

	lea	Water_Wobble(a6),a0
	move.w	#224*2,d0
	move.w	#$f002,a1
	bsr	AddDMA
	move.b	#$04,DMA_Inc+1(a2)

	lea	Water_Wobble(a6),a0

	move.w	YStart(a6),d1

	lea	Water_YHelp(a6),a2
	moveq	#0,d4
.wobble_loop2:
	move.w	(a2)+,d2		;Diesen X-Scrollwert
	move.w	(a2),d7			;Bis zu dieser Zeile.
	sub.w	d4,d7
	move.w	(a2)+,d4

	lea	Water_Sinus(pc),a1
	lea	(a1,d1.w),a1
.wobble_loop:
	move.b	(a1)+,d0
	ext.w	d0
	add.w	d2,d0
	move.w	d0,(a0)+

	dbf	d7,.wobble_loop

	cmp.w	#224,d4
	blt.s	.wobble_loop2

	addq.w	#1,YStart(a6)
	and.w	#$ff,YStart(a6)

.only_colors:
	bsr	Bewege_Bubbles
	lea	Water_Fade_Struktur(a6),a0
	bsr	Call_Transformation2

		rts

Copper_WaterSplit:
	move.w	#$2700,sr
	movem.l	a0-a1/d0-d1,-(sp)

	;SetColor
	move.w	WCopper_Help+4(a6),d0
	lea	WatPCol1,a0
	lea	(a0,d0.w),a0

.waithbl:
	cmp.b	#250/2,$c00009
	blo.s	.waithbl

	move.l	(a0)+,d0
	move.w	(a0)+,d1
	move.l	a0,-(sp)
	lea	$c00000,a0
	move.l	#$c0700000,4(a0)
	move.l	d0,(a0)
	move.w	d1,(a0)

	move.w	WCopper_Help(a6),d0

.waithbloff:
	btst	#2,$c00005
	bne.s	.waithbloff

	move.w	#$8f04,$c00004
	move.l	#$40000010+$00020000,$c00004		;Vertikaler Split
	lea	WCopper_Wabbel(a6),a1

	moveq	#19,d1
.loop:
	add.w	(a1)+,d0
	move.w	d0,$c00000
	dbf	d1,.loop

	move.w	#$8f02,$c00004

	move.l	Copper_Pointer(a6),a0
	move.w	(a0)+,d0			;In Dieser Zeile wird der Nchste Ausgelst!
	move.l	(a0)+,Int_HBlank+2(a6)
	move.l	a0,Copper_Pointer(a6)
	move.w	(a0),d1
	sub.w	d0,d1
	subq.w	#1,d1
	and.w	#$00ff,d1
	or.w	#$8a00,d1
	move.w	d1,$c00004

;	move.l	#$40000000+$30020003,$c00004		;Horizontaler Split
;	move.w	WCopper_Help+2(a6),$c00000

	move.l	WCopper_TabPointer(a6),a0
	move.l	(a0)+,WCopper_Help(a6)
	move.w	(a0)+,WCopper_Help+4(a6)
	move.l	a0,WCopper_TabPointer(a6)

	move.l	(sp)+,a0

.waithbl2:
	cmp.b	#255/2,$c00009
	blo.s	.waithbl2

	nop

	move.l	(a0)+,d0
	move.w	(a0)+,d1
	lea	$c00000,a0
	move.l	#$c0760000,4(a0)
	move.l	d0,(a0)
	move.w	d1,(a0)

	movem.l	(sp)+,a0-a1/d0-d1

	rte

Copper_InitWater:
	move.l	Copper_List(a6),a0
	addq.l	#4,a0
	movem.l	a0-a1/d1,-(sp)

	move.l	WYPos_Pointer(a6),a0
	move.l	#$40000010+$00020000,$c00004
	move.w	(a0),d1
	move.w	(a0)+,$c00000
	move.l	#$40000000+$30020003,$c00004
	move.w	(a0)+,$c00000
	move.w	(a0)+,d0			;Color-List
	move.l	(a0)+,WCopper_Help(a6)
	move.w	(a0)+,WCopper_Help+4(a6)
	move.l	a0,WCopper_TabPointer(a6)

	lea	WatPCol1,a0
	lea	(a0,d0.w),a0

	move.l	#$c0700000,$c00004

	move.l	(a0)+,$c00000
	move.l	(a0)+,$c00000
	move.l	(a0)+,$c00000

	move.w	#$8f04,$c00004
	move.l	#$40000010+$00020000,$c00004		;Vertikaler Split

	move.w	d1,d0
	moveq	#19,d1
	lea	WCopper_Wabbel(a6),a1
.loop:
	add.w	(a1)+,d0
	move.w	d0,$c00000
	dbf	d1,.loop

	move.w	#$8f02,$c00004

	movem.l	(sp)+,a0-a1/d1
	rts

Generate_Wabbel:
	lea	WCopper_Struktur(a6),a0
	lea	WCopper_Wabbel(a6),a1
	lea	WCopper_Table(pc),a2
	moveq	#19,d7
	moveq	#0,d1
.loop:
	subq.w	#1,WCopper_Verz(a0)
	bpl.s	.next

	move.w	WCopper_VerzDef(a0),WCopper_Verz(a0)
	addq.w	#2,WCopper_Pos(a0)
	and.w	#6,WCopper_Pos(a0)
.next:
	move.w	WCopper_Pos(a0),d0
	move.w	(a2,d0.w),d0
	sub.w	d1,d0
	add.w	d0,d1
	move.w	d0,(a1)

	addq.l	#2,a1
	lea	WCopper_Len(a0),a0
	dbf	d7,.loop

	rts

WCopper_Table:	dc.w	0,-1,-2,-1

Init_Wabbel:
	lea	WCopper_Default(pc),a0
	lea	WCopper_Struktur(a6),a1
	moveq	#20*WCopper_Len-1,d7
.loop:
	move.w	(a0)+,(a1)+
	dbf	d7,.loop
	rts

		rsreset
WCopper_Verz	rs.w	1
WCopper_VerzDef	rs.w	1
WCopper_Pos	rs.w	1
WCopper_Len	rs.w	0

WCopper_Default:
	dc.w	5,5,0, 2,5,2, 6,5,4, 1,5,6
	dc.w	2,8,0, 4,8,2, 3,8,4, 3,8,6
	dc.w	4,6,0, 0,6,2, 1,6,4, 5,6,6
	dc.w	1,7,0, 2,7,2, 4,5,4, 3,7,6
	dc.w	3,5,0, 3,5,2, 2,5,4, 5,5,6

;--------------------------------------------------------------------------
LAX_WATER_PARA		EQU	0

WMaxLAX_ScrollVals	dc.w	0*48,1*48,2*48,3*48,4*48,5*48,6*48
WGLOBAL_SCRVAL	=112+90
WAnzParaLax	dc.w	6-1
WLax_Entry_Tab
WLAX_W1		;---------------- LAX 01
		dc.w	LAX_WATER_PARA
		dc.w	WatPCol1-WatPCol1	;Lax_Copper_Entry1
		dc.w	$2f+000		;Lax_Y_WaitPos
		dc.w	02		;Lax_Pos_Val/16
		dc.w	112		;Lax_Max_Hight
WLAX_W2		;---------------- LAX 02
		dc.w	LAX_WATER_PARA
		dc.w	WatPCol2-WatPCol1		;Lax_Copper_Entry1
		dc.w	$2f+112		;Lax_Y_WaitPos
		dc.w	04		;Lax_Pos_Val/16
		dc.w	112		;Lax_Max_Hight
WLAX_W3		;---------------- LAX 03
		dc.w	LAX_WATER_PARA
		dc.w	WatPCol3-WatPCol1		;Lax_Copper_Entry1
		dc.w	$2f+2*112		;Lax_Y_WaitPos
		dc.w	06		;Lax_Pos_Val/16
		dc.w	112		;Lax_Max_Hight
WLAX_W4		;---------------- LAX 04
		dc.w	LAX_WATER_PARA
		dc.w	WatPCol4-WatPCol1	;Lax_Copper_Entry1
		dc.w	$2f+3*112		;Lax_Y_WaitPos
		dc.w	08		;Lax_Pos_Val/16
		dc.w	112		;Lax_Max_Hight
WLAX_W5		;---------------- LAX 05
		dc.w	LAX_WATER_PARA
		dc.w	WatPCol5-WatPCol1		;Lax_Copper_Entry1
		dc.w	$2f+4*112		;Lax_Y_WaitPos
		dc.w	10		;Lax_Pos_Val/16
		dc.w	112		;Lax_Max_Hight
WLAX_W6		;---------------- LAX 06
		dc.w	LAX_WATER_PARA
		dc.w	WatPCol6-WatPCol1		;Lax_Copper_Entry1
		dc.w	$2f+5*112+40		;Lax_Y_WaitPos
		dc.w	12		;Lax_Pos_Val/16
		dc.w	112		;Lax_Max_Hight

WLAX_FAKE		;---------------- LAX FAKE
		dc.w	0		;Lax_Gfx_Anf
		dc.w	WatPCol1-WatPCol1	;Lax_Copper_Entry1
		dc.w	$2f+208		;Lax_Y_WaitPos
		dc.w	8		;Lax_Pos_Val/16
		dc.w	112		;Lax_Max_Hight

WaterParaCols:
		dc.w	$fd8,$fff,$ffd,$fda,$fb6,$f94,$fd8
		dc.w	$f94,$fff,$ffa,$fb6,$f63,$c42,$f94
		dc.w	$c42,$fed,$fc7,$f80,$d30,$800,$c42
		dc.w	$800,$fdd,$f9c,$e5a,$b36,$504,$800
		dc.w	$504,$edf,$88e,$81c,$508,$205,$504
		dc.w	$205,$9cf,$17e,$03c,$008,$006,$205
		dc.w	$205,$9cf,$17e,$03c,$008,$006,$205

		rsset	Water_Fade_Struktur+Fade_Palette+WorkRam
WatPCol1:	rs.w	7
WatPCol2:	rs.w	7
WatPCol3:	rs.w	7
WatPCol4:	rs.w	7
WatPCol5:	rs.w	7
WatPCol6:	rs.w	7
WatPCol7:	rs.w	7

;WatPCol1:
;		dc.w	$8df,$fff,$dff,$adf,$6bf
;		dc.w	$49f,$8df
;WatPCol2:
;		dc.w	$49f,$fff,$aff,$6bf,$36f
;		dc.w	$24c,$49f
;WatPCol3:
;		dc.w	$24c,$def,$7cf,$08f,$03d
;		dc.w	$008,$24c
;WatPCol4:
;		dc.w	$008,$ddf,$c9f,$a5e,$63b
;		dc.w	$405,$008
;WatPCol5:
;		dc.w	$405,$fde,$e88,$c18,$805
;		dc.w	$502,$405
;WatPCol6:
;		dc.w	$502,$fc9,$e71,$c30,$800
;		dc.w	$600,$502
;WatPCol7:
;		dc.w	$502,$fc9,$e71,$c30,$800
;		dc.w	$600,$502

Water_PBase	= $6000+Water_ParaVRam/32	;$2190

;-------------- Initialisiert Parallax-Playfield
Init_WaterParallax:

	lea	Water_para_bin_p,a0
	lea	Water_ParaVRam,a1
	jsr	LoadVRam_crunched

	lea	BUBBLE_raw,a0
	move	#832,d0
	lea	Water_PBubblesVRam,a1
	jsr	LoadVRam_crunched

	move	#$8f02,$c00004

	move.w	#$2700,sr

	lea	water_parablock1(pc),a0
	move	#$c000,d0
	moveq	#15,d5
.loop5:
	bsr	SetVRamAdress

	moveq	#4,d6
.loop4:
	move.l	a0,a1
	moveq	#9,d7
.loop3:
	move	(a1)+,d1
	add.w	#Water_PBase,d1
	move.w	d1,$c00000
	dbf	d7,.loop3
	dbf	d6,.loop4

	lea	20(a0),a0
	add	#$80,d0
	dbf	d5,.loop5

	add.w	#$80*13,d0

	moveq	#2,d5
.loop7:
	bsr	SetVRamAdress
	moveq	#50,d6
.loop6:
	move.w	#Water_PBase+01,$c00000
	dbf	d6,.loop6
	add.w	#$80,d0
	dbf	d5,.loop7

	;Create CopperLists

	lea	Water_CopperList1(a6),a0
	lea	Water_CopperList2(a6),a1
	move.l	#Copper_InitWater,(a0)+
	move.w	#$ff,(a0)+
	move.l	#Copper_InitWater,(a1)+
	move.w	#$ff,(a1)+
	moveq	#15-1,d7
.loop:
	move.l	#Copper_WaterSplit,(a0)+
	move.w	#$ff,(a0)+
	move.l	#Copper_WaterSplit,(a1)+

	move.w	#$ff,(a1)+
	dbf	d7,.loop
	move.l	#Int_Nop,(a0)+
	move.l	#Int_Nop,(a1)+

	lea	WYPos_Table1(a6),a0
	lea	WYPos_Table2(a6),a1
	move.l	a0,WYPos_Pointer(a6)
	move.l	a1,WYPos_Buffer(a6)

	moveq	#6,d7
.init_ypostable:
	clr.l	(a0)+
	clr.w	(a0)+
	clr.l	(a1)+
	clr.w	(a1)+
	dbf	d7,.init_ypostable

	bsr	Init_Wabbel

	lea	Water_Fade_Struktur(a6),a0
	lea	Black_Coltab,a1
	lea	WaterParaCols(pc),a2

	move.w	#49-1,d0
	bsr	Init_Transformation
	move.l	#Init_WaterParaFadeOut,Init_ParaFadeOut(a6)

	move.w	#$8b07,$c00004
	st	Scr_SplitScroll(a6)

	move.l	#Water_CopperList1+WorkRam,Copper_List(a6)
	move.l	#Water_CopperList2+WorkRam,Copper_Buffer(a6)

	bsr	Init_Bubbles
	clr.w	YStart(a6)

	move.w	#$2300,sr

	rts

Init_WaterParaFadeOut:
	lea	Water_Fade_Struktur(a6),a0
	lea	WaterParaCols(pc),a1
	lea	Black_Coltab,a2

	move.w	#49-1,d0
	jmp	Init_Transformation

water_parablock1:
	dc.w	01,01,01,01,01,01,01,01,01,01
	dc.w	00,01,01,01,01,01,01,01,40,41
	dc.w	02,03,01,01,01,01,01,56,42,43
	dc.w	04,05,01,01,01,01,32,33,44,45
	dc.w	06,07,16,17,01,15,34,35,46,47
	dc.w	08,09,20,21,24,25,36,37,48,49
	dc.w	10,11,22,23,26,27,38,39,50,51
	dc.w	12,13,14,14,28,29,18,19,52,53
	dc.w	14,14,14,14,30,31,14,57,54,55
	dc.w	14,14,14,14,14,14,14,14,14,14
	dc.w	14,14,14,14,14,14,14,14,14,14
	dc.w	14,14,14,14,14,14,14,14,14,14
	dc.w	14,14,14,14,14,14,14,14,14,14
	dc.w	14,14,14,14,14,14,14,14,14,14
	dc.w	14,14,14,14,14,14,14,14,14,14
	dc.w	14,14,14,14,14,14,14,14,14,14

**************************************************************************************
*-------------------------------------------------------------------------------------
*----------------	SPR BUBBLES    SPR BUBBLES    SPR BUBBLES    SPR BUBBLES    
*-------------------------------------------------------------------------------------
BUBBLE_SPRITES		EQU	2
BUBBLE_PER_SPRITE	EQU	8
BUBBLE_UPPER_CLIP	EQU	40
BUBBLE_LOWER_CLIP	EQU	276
BUBBLE_SINUS_EACH	EQU	36
BUBBLE_SINUS_ANZ	EQU	9

Bewege_Bubbles:
		;Hole Zeiger auf Verwaltungs-Struktur
		move.l	Sig_VRam_Pointer(a6),a4

		moveq	#BUBBLE_SPRITES-1,d7
		lea	Bubble_Zeiger_Liste(a6),a0

		;Hole Parameter fr nchste Bubble
.Loop_Sprites:
		;Geschwindkeit der vertikalen Bewegung
		move	Bubble_Speed(a0),d5
		add	d5,Bubble_Float(a0)
		moveq	#0,d5
		move.b	Bubble_Float(a0),d5
		clr.b	Bubble_Float(a0)
		add	Scr_Y_Real_Speed(a6),d5

		;Oben oder unten abtesten ???
		tst	d5
		bmi	.Test_lower_Clip

		;Erstes Element der Sprite-Liste auerhalb ???
		move.l	Bubble_Pointer(a0),a1
		cmp	#BUBBLE_UPPER_CLIP,WSprite_Y_Position(a1)
		bhs	.Clip_Ok

		;Sprite-Listen sortieren (UPPER_CLIP)
.Upper_Clip	move.l	Bubble_Sprite_2(a0),a3
		move.l	Bubble_Sprite_1(a0),Bubble_Sprite_2(a0)
		move.l	a3,Bubble_Sprite_1(a0)
		add	#BUBBLE_LOWER_CLIP-BUBBLE_UPPER_CLIP,WSprite_Y_Position(a1)
		add.l	#WSPRITE_ENTRY_LENGTH,Bubble_Pointer(a0)
		move.l	Bubble_Pointer(a0),a3
		tst	(a3)
		bpl.s	.Hole_neue_Position
		move.l	Bubble_Reset(a0),Bubble_Pointer(a0)

		;Hole vertikale Position nach Clip
.Hole_neue_Position	lea	Bubble_Positionen,a3
		add	Bubble_Pos_Offset(a6),a3
		move	(a3),d3
		bpl.s	.New_Pos_Ok
		clr	Bubble_Pos_Offset(a6)
		bra.s	.Hole_neue_Position
.New_Pos_Ok	move	d3,WSprite_X_Position(a1)
		addq	#WORD,Bubble_Pos_Offset(a6)
		bra	.Clip_Ok

		;Letztes Element der Sprite-Liste auerhalb ???
.Test_lower_Clip	move.l	Bubble_Pointer(a0),a1
		cmp.l	Bubble_Reset(a0),a1
		bne	.Nicht_erstes
		move.l	Bubble_Reset(a0),a1
		add	#WSPRITE_ENTRY_LENGTH*BUBBLE_PER_SPRITE,a1
.Nicht_erstes	sub	#WSPRITE_ENTRY_LENGTH,a1
		cmp	#BUBBLE_LOWER_CLIP,WSprite_Y_Position(a1)
		blo	.Clip_Ok

		;Sprite-Listen sortieren (LOWER_CLIP)
.Lower_Clip	move.l	Bubble_Sprite_2(a0),a3
		move.l	Bubble_Sprite_1(a0),Bubble_Sprite_2(a0)
		move.l	a3,Bubble_Sprite_1(a0)
		sub	#BUBBLE_LOWER_CLIP-BUBBLE_UPPER_CLIP,WSprite_Y_Position(a1)
		move.l	Bubble_Reset(a0),a3
		cmp.l	Bubble_Pointer(a0),a3
		bne.s	.Geht_noch
		add.l	#WSPRITE_ENTRY_LENGTH*BUBBLE_PER_SPRITE,Bubble_Pointer(a0)
.Geht_noch	sub.l	#WSPRITE_ENTRY_LENGTH,Bubble_Pointer(a0)
		bra.s	.Hole_neue_Position

		;Verwalte Animation
.Clip_Ok
		subq	#1,Bubble_Zhler(a0)
		bpl	.Anim_Ok
		move	Bubble_Zhler_Reset(a0),Bubble_Zhler(a0)
		move.l	Bubble_Sprite_2(a0),a3
		move.l	Bubble_Sprite_1(a0),Bubble_Sprite_2(a0)
		move.l	a3,Bubble_Sprite_1(a0)

		;Zeiger auf Spriteliste in Copperliste schreiben
.Anim_Ok
		move.l	Bubble_Sprite_1(a0),a2
		move.l	a2,d0

		;Hole Parameter fr nchste Bubble
		moveq	#BUBBLE_PER_SPRITE-1,d6
		move.l	Bubble_Pointer(a0),a1
		move.w	Sig_LinkData(a6),d4

		;Geschwindkeit der vertikalen Bewegung

		;Hole Position und Hhe der nchsten Bubble
.Loop_2		move	WSprite_X_Position(a1),d0
		bpl.s	.Ok2
		move.l	Bubble_Reset(a0),a1
		bra.s	.Loop_2
.Ok2		move	WSprite_Y_Position(a1),d1

		;Kontrollwrter fr aktuelle Bubble erzeugen
		move.l	Bubble_Sprite_1(a0),a5

		add.w	#70,d1
		move.w	d1,(a4)+
		move.w	(a5)+,(a4)+
		move.b	d4,-1(a4)
		move.w	(a5)+,(a4)+
		sub.w	#48,d0
		move.w	d0,(a4)+

		addq.w	#1,d4

		;Bubbles wackeln lassen.

		move.l	Bubble_Vertical(a0),a3
		add	WSprite_Offset(a1),a3
		move.b	(a3),d3
		ext	d3
		add	d3,WSprite_X_Position(a1)
		addq	#BYTE,WSprite_Offset(a1)
		cmp	#BUBBLE_SINUS_EACH*BUBBLE_SINUS_ANZ,WSprite_Offset(a1)
		blo.s	.Offset_Ok
		sub	#BUBBLE_SINUS_EACH,WSprite_Offset(a1)

		;Bubble mitscrollen
.Offset_Ok	move.w	Scr_X_Real_Speed(a6),d3
		sub.w	d3,WSprite_X_Position(a1)

		;Horizontale Positionen clippen
		cmp.w	#7*16,WSprite_X_Position(a1)
		bhs.s	.Links_Ok
		add.w	#24*16,WSprite_X_Position(a1)
		bra.s	.Rechts_Ok
.Links_Ok	cmp.w	#(8+24)*16,WSprite_X_Position(a1)
		blo.s	.Rechts_Ok
		sub.w	#24*16,WSprite_X_Position(a1)
.Rechts_Ok	sub.w	d5,WSprite_Y_Position(a1)

		;Schleife ber alle Bubbles
		add	Bubble_Offset(a0),a2
		addq	#WSPRITE_ENTRY_LENGTH,a1
		dbf	d6,.Loop_2

		move.w	d4,Sig_LinkData(a6)

		;Schleife ber alle Sprites
		lea	BUBBLE_ENTRY_LENGTH(a0),a0
		dbf	d7,.Loop_Sprites

		;und zurck
.Done
		move.l	a4,Sig_VRam_Pointer(a6)
		rts

Init_Bubbles:
		clr	Bubble_Pos_Offset(a6)
		lea	Bubble_Zeiger_Liste_Default(pc),a0
		lea	Bubble_Zeiger_Liste(a6),a1
		move.w	#BUBBLE_ENTRY_LENGTH+50-1,d7
.copy:
		move.l	(a0)+,(a1)+
		dbf	d7,.copy
		rts

Bubble_Info0:	dc.w	$0500
		dc.w	$8000+Water_PBubblesVRam/32
Bubble_Info1:	dc.w	$0500
		dc.w	$8004+Water_PBubblesVRam/32
Bubble_Info2:	dc.w	$0500
		dc.w	$8008+Water_PBubblesVRam/32
Bubble_Info3:	dc.w	$0500
		dc.w	$800C+Water_PBubblesVRam/32
Bubble_Info4:	dc.w	$0500
		dc.w	$8010+Water_PBubblesVRam/32
Bubble_Info5:	dc.w	$0100
		dc.w	$8014+Water_PBubblesVRam/32
Bubble_Info6:	dc.w	$0100
		dc.w	$8016+Water_PBubblesVRam/32
Bubble_Info7:	dc.w	$0100
		dc.w	$8018+Water_PBubblesVRam/32


Bubble_Zeiger_Liste_Default:
		dc.w	16-1
		dc.w	(16-1)*LONG
		dc.w	256,0
		dc.w	0,8
		dc.l	Bubble_Liste_1-Bubble_Zeiger_Liste_Default+WorkRam+Bubble_Zeiger_Liste
		dc.l	Bubble_Liste_1-Bubble_Zeiger_Liste_Default+WorkRam+Bubble_Zeiger_Liste
		dc.l	Bubble_Info0
		dc.l	Bubble_Info1
		dc.l	Bubble_Vert_4

		dc.w	14-1
		dc.w	(14-1)*LONG
		dc.w	128,0
		dc.w	2,8
		dc.l	Bubble_Liste_2-Bubble_Zeiger_Liste_Default+WorkRam+Bubble_Zeiger_Liste
		dc.l	Bubble_Liste_2-Bubble_Zeiger_Liste_Default+WorkRam+Bubble_Zeiger_Liste
		dc.l	Bubble_Info2
		dc.l	Bubble_Info3
		dc.l	Bubble_Vert_3

		dc.w	12-1
		dc.w	(12-1)*LONG
		dc.w	64,0
		dc.w	4,8
		dc.l	Bubble_Liste_3-Bubble_Zeiger_Liste_Default+WorkRam+Bubble_Zeiger_Liste
		dc.l	Bubble_Liste_3-Bubble_Zeiger_Liste_Default+WorkRam+Bubble_Zeiger_Liste
		dc.l	Bubble_Info4
		dc.l	Bubble_Info5
		dc.l	Bubble_Vert_2

		dc.w	10-1
		dc.w	(10-1)*LONG
		dc.w	32,0
		dc.w	6,8
		dc.l	Bubble_Liste_4-Bubble_Zeiger_Liste_Default+WorkRam+Bubble_Zeiger_Liste
		dc.l	Bubble_Liste_4-Bubble_Zeiger_Liste_Default+WorkRam+Bubble_Zeiger_Liste
		dc.l	Bubble_Info6
		dc.l	Bubble_Info7
		dc.l	Bubble_Vert_1

Bubble_Liste_1	dc.w	190,050,320
		dc.w	424,070,288
		dc.w	370,094,249
		dc.w	236,112,220
		dc.w	345,138,179
		dc.w	246,158,147
		dc.w	129,186,102
		dc.w	205,216,054
		dc.w	-1

Bubble_Liste_2	dc.w	205,045,308
		dc.w	129,061,303
		dc.w	246,085,314
		dc.w	345,105,299
		dc.w	236,127,314
		dc.w	370,153,248
		dc.w	424,183,171
		dc.w	190,213,094
		dc.w	-1

Bubble_Liste_3	dc.w	257,060,290
		dc.w	302,080,309
		dc.w	286,106,312
		dc.w	418,130,320
		dc.w	154,158,245
		dc.w	423,181,184
		dc.w	302,208,112
		dc.w	161,228,058
		dc.w	-1

Bubble_Liste_4	dc.w	308,080,320
		dc.w	318,106,305
		dc.w	418,128,302
		dc.w	287,152,294
		dc.w	257,180,235
		dc.w	308,200,168
		dc.w	161,222,094
		dc.w	154,240,033
		dc.w	-1

		rsreset
WSprite_X_Position	rs.w	1
WSprite_Y_Position	rs.w	1
WSprite_Offset		rs.w	1
WSPRITE_ENTRY_LENGTH	rs.w	0


Bubble_Positionen	dc.w	257,287,308,310,392,318,431,215,142,427
			dc.w	154,423,302,207,413,138,418,335,286,161,-1

Bubble_Vert_1	Incbin	Binary/Water/Sinus_1_DAT
Bubble_Vert_2	Incbin	Binary/Water/Sinus_2_DAT
Bubble_Vert_3	Incbin	Binary/Water/Sinus_3_DAT
Bubble_Vert_4	Incbin	Binary/Water/Sinus_4_DAT

Water_Sinus:
	dc.b	0,1,1,1,1,1,0,0,0,-1,-1,-1,-1,-1,0,0		;0
	dc.b	0,1,1,1,1,1,0,0,0,-1,-1,-1,-1,-1,0,0		;1
	dc.b	0,1,1,1,1,1,0,0,0,-1,-1,-1,-1,-1,0,0		;2
	dc.b	0,1,1,1,1,1,0,0,0,-1,-1,-1,-1,-1,0,0		;3
	dc.b	0,1,1,1,1,1,0,0,0,-1,-1,-1,-1,-1,0,0		;4
	dc.b	0,1,1,1,1,1,0,0,0,-1,-1,-1,-1,-1,0,0		;5
	dc.b	0,1,1,1,1,1,0,0,0,-1,-1,-1,-1,-1,0,0		;6
	dc.b	0,1,1,1,1,1,0,0,0,-1,-1,-1,-1,-1,0,0		;7
	dc.b	0,0,1,1,1,1,2,2,2,2,2,2,1,1,1,1,0,0
	dc.b	-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,-1,-1,-1,-1
	dc.b	0,0,1,1,1,1,2,2,2,2,2,2,1,1,1,1,0,0
	dc.b	-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,-1,-1,-1,-1
	dc.b	0,0,1,1,1,1,2,2,2,2,2,2,1,1,1,1,0,0
	dc.b	-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,-1,-1,-1,-1
	dc.b	0,0,1,1,1,1,2,2,2,2,2,2,1,1,1,1,0,0
	dc.b	-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,-1,-1,-1,-1

	dc.b	0,1,1,1,1,1,0,0,0,-1,-1,-1,-1,-1,0,0		;0
	dc.b	0,1,1,1,1,1,0,0,0,-1,-1,-1,-1,-1,0,0		;1
	dc.b	0,1,1,1,1,1,0,0,0,-1,-1,-1,-1,-1,0,0		;2
	dc.b	0,1,1,1,1,1,0,0,0,-1,-1,-1,-1,-1,0,0		;3
	dc.b	0,1,1,1,1,1,0,0,0,-1,-1,-1,-1,-1,0,0		;4
	dc.b	0,1,1,1,1,1,0,0,0,-1,-1,-1,-1,-1,0,0		;5
	dc.b	0,1,1,1,1,1,0,0,0,-1,-1,-1,-1,-1,0,0		;6
	dc.b	0,1,1,1,1,1,0,0,0,-1,-1,-1,-1,-1,0,0		;7
	dc.b	0,0,1,1,1,1,2,2,2,2,2,2,1,1,1,1,0,0
	dc.b	-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,-1,-1,-1,-1
	dc.b	0,0,1,1,1,1,2,2,2,2,2,2,1,1,1,1,0,0
	dc.b	-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,-1,-1,-1,-1
	dc.b	0,0,1,1,1,1,2,2,2,2,2,2,1,1,1,1,0,0
	dc.b	-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,-1,-1,-1,-1
	dc.b	0,0,1,1,1,1,2,2,2,2,2,2,1,1,1,1,0,0
	dc.b	-1,-1,-1,-1,-2,-2,-2,-2,-2,-2,-1,-1,-1,-1

	ENDC